import type { Module } from 'vuex'
import type { RouteMenus } from "../types";
import { constantRouteMenus } from "@/router";
import { treeToAscending,filterMenuTree } from "@/router/utils";

const routeMenusModule: Module<RouteMenus,any> = {
  namespaced: true,
  state: {
    // 路由菜单数据
    routeMenus: [],
  },
  mutations:{},
  actions: {
    // 获取所有路由菜单数据（静态+动态获取部分）
    getWholeRouteMenus({state},routes) {
      if(state.routeMenus.length > 0){
        return;
      }
      state.routeMenus = filterMenuTree(treeToAscending(constantRouteMenus.concat(routes)));
      console.log(state.routeMenus,"菜单数据");
    },
  }
};
export default routeMenusModule